﻿@model IList<COMCMS.Core.ArticleCategory>
@{
    ViewBag.title = "文章栏目管理";
}

<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>@ViewBag.Title</h5>
        </div>
        <div class="ibox-content">
            <div id="toolbar" class="btn-group">
                <button id="btn_add" type="button" class="btn btn-outline btn-default" onclick="showDialog('addarticlekind','添加文章栏目','/AdminCP/Article/AddArticleCategory',0,0);">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                </button>
            </div>

            <div id="toolbar2" class="btn-group pull-right">
                <button id="btn_refresh" type="button" class="btn btn-outline btn-default" onclick="refresh();">
                    <span class="fa fa-refresh" aria-hidden="true"></span>刷新
                </button>
            </div>
            <table class="tree table table-striped table-bordered">
                <thead>
                    <tr>
                        <th>栏目名称</th>
                        <th>ID</th>
                        <th class="text-center" style="width:130px">排序</th>
                        <th class="text-center">文章数量</th>
                        <th class="text-center">隐藏</th>
                        <th width="200">操作</th>
                    </tr>
                </thead>
                @if (Model.Count == 0)
                {
                    <tr><td colspan="6" class="text-center">暂无记录...</td></tr>
                }
                @foreach (var m in Model)
                {
            <tr class="treegrid-@m.Id @(m.PId !=0?"treegrid-parent-"+m.PId:"") ">
                <td>@m.KindName</td>
                <td>
                    @m.Id
                </td>
                <td class="text-center">
                    <div class="input-group"><input type="number" class="form-control" id="ac_rank_@(m.Id)" name="ac_rank_@(m.Id)" value="@m.Rank" placeholder="请输入一个数字，越小排越前"><a class="input-group-addon btn btn-primary" title="修改保存" href="javascript:;" onclick="doSaveRank(@(m.Id))"><i class="fa fa-save"></i></a></div>
                </td>
                <td class="text-center">@m.Counts</td>
                <td class="text-center">
                    @if (m.IsHide == 1)
                    {
                        <i class="fa fa-eye-slash"></i>
                    }
                </td>
                <td>
                    <a href="javascript:;" class="btn btn-xs btn-primary" title="编辑" onclick="top.showDialog('eidtarticlekind', '编辑文章栏目详情', '/AdminCP/Article/EditArticleCategory/@m.Id', 0, 0)"><i class="fa fa-edit"></i> 编辑</a>
                    <a href="javascript:;" class="btn btn-xs btn-danger" title="删除" onclick="doDel('/AdminCP/Article/DelArticleCategory',@m.Id);"><i class="fa fa-close"></i> 删除</a>
                </td>
            </tr>
                }
            </table>
            <script type="text/javascript">
                    $(document).ready(function() {
                        $('.tree').treegrid();
                    });
                function doSaveRank(id) {
                    var rank = $("#ac_rank_" + id).val();
                    if (rank == '') {
                        layer.alert("请输入排序！", { icon: 2 });
                        return false;
                    }
                    //console.log(rank);
                    if (!isInt(rank)) {
                        layer.alert("排序只能是数字！", { icon: 2 });
                        return false;
                    }
                    var loading = layer.load(0, {
                        shade: [0.2, '#000'] //0.1透明度的背景
                    });
                    $.ajax({
                        type: "POST",
                        url: "/AdminCP/Article/DoEditCategoryRank",
                        data: { id: id, rank: rank },
                        dataType: "JSON",
                        success: function (data) {
                            if (data.status == "success") {
                                layer.close(loading);
                                layer.msg(data.message, {
                                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                                }, function () {
                                    //window.location.href = window.location.href;
                                });
                            } else {
                                layer.close(loading);
                                layer.alert(data.message, { icon: 2 });
                            }
                        },
                        error: function () {
                            layer.close(loading);
                            layer.alert('执行错误，请联系管理员！', { icon: 2 });
                        }
                    });
                }
            </script>
        </div>
    </div>


</div>